#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

typedef struct __group
{
    struct __group *last;
    int group[3];
    struct __group *next;

} _GROUP;

_GROUP *newGroup(_GROUP *_last);
_GROUP *construct(_GROUP *__last);
int freeGroup( _GROUP *_any);
_GROUP *backToHead( _GROUP *_any);
int printInfo( _GROUP *_head);

int main()
{
    _GROUP *group1 = newGroup(NULL);

    int a, b, c, T, n, i, j, sum = 0, data[30];
    scanf("%d", &T);
    // 单独用数组把数据存起来，再让它分别输出
    for (j = 0; j < T; j++)
        scanf("%d", &data[j]);

    printf("****************************\n");
    for (j = 0; j < T; j++)
    {
        sum = 0;
        n = data[j];
        for (a = 0; a <= n; a++)
        {
            for (b = 0; b <= n - a; b++)
            {
                for (c = 0; c <= n - a - b; c++)
                {
                    if (a + b + c == n && 5 * a + 3 * b + c / 3 == n && c % 3 == 0)
                    {
                        if (sum == 0)
                        {
                            group1->group[0] = b;
                            group1->group[1] = a;
                            group1->group[2] = c;
                        }
                        else
                        {
                            group1 = newGroup(group1);
                            group1->group[0] = b;
                            group1->group[1] = a;
                            group1->group[2] = c;
                        }
                        sum++;
                    }
                }
            }
        }
    }
    // 控制流程需要--
    sum--;
    printf("sum\n%d\n", sum);
    // printf("%d %d %d\n",a,b,c);(你需要将所有的情况都输出出来，所以你得把输出语句放入循环里)
    _GROUP* head = backToHead(group1);
    printInfo(head);
    freeGroup(head);
    head = NULL;
    return 0;
}

_GROUP *newGroup(_GROUP *_last)
{
    static char determineOnlyOne = 0;
    _GROUP *last = _last;
    _GROUP *recv = NULL;

    if (last == NULL)
        if (determineOnlyOne == 0)
        {
            recv = construct(last);
            determineOnlyOne = 1;
        }
        else
        {
            puts("已存在链表头, 无法添加!");
            return NULL;
        }
    else
        recv = construct(last);

    return recv;
}

_GROUP *construct(_GROUP *__last)
{
    static char determineOnlyOnece = 0;
    _GROUP *_data = NULL;
    if(__last == NULL)
    {
        if(determineOnlyOnece == 0)
        {
            _data = malloc(sizeof(_GROUP));
            _data->last = NULL;
            memset(_data->group,0,sizeof(_data->group));
            _data->next = NULL;
            return _data;
        }
    }
    else
    {
        _data = malloc(sizeof(_GROUP));
        _data->last = __last;
        __last->next = _data;

        memset(_data->group,0,sizeof(_data->group));

        _data->next = NULL;
    }
    
    return _data;
}

int freeGroup( _GROUP *_any)
{
    // 转到尾部
    _GROUP *any = _any;
    if (any->next != NULL)
    {
        freeGroup((any = any->next));
    }
    else
    {
        if (any->last != NULL)
        {
            any = any->last;
            free(any->next);
        }
        else
        {
            free(any);
            return 0;
        }
    }
}

_GROUP *backToHead( _GROUP *_any)
{
    _GROUP *any = _any;
    assert(any);
    if (any == NULL)
        return NULL;

    if (any->last != NULL)
    {
        backToHead((any = any->last));
    }
    else
        return any;
}

int printInfo( _GROUP *_head)
{
    _GROUP *head = _head;
    static size_t count = 0;
    assert(head);
    if (head == NULL)
        return -1;
    
    if(head->next == NULL)
        return 0;

    assert(head->next);

    if (head->next != NULL)
    {
        printf("%d\t%d\t%d\n", head->group[0], head->group[1], head->group[2]);
        count++;
        if (head->next == NULL)
            return 0;
        printInfo((head = head->next));
    }
}